/**
 * 协议中的指令分类
 */

// MARK: - 常量

/// 时间前缀
const secondForThirtyYear = 946684800

/// 当地GMT时间(秒)
const secondFromGMT = (new Date()).getTimezoneOffset() * 60

/// 深睡标志
const deepSleepFlag = 0xF1

/// 浅睡标志
const lightSleepFlag = 0xF2

/// 眼动标志
const remSleepFlag = 0xF3

/// 清醒标志
const awakeSleepFlag = 0xF4

// MARK: - 错误分类

// 成功
const succeed = 0

// 失败
const failed = 1

// 超时
const timeout = 2

// 不可用
const unavailable = 3

// 数据错误
const dataError = 4

//  crc错误
const crcError = 5

// 没有记录
const noRecord = 6

// 类型不支持
const typeNotSupport = 7

// 参数错误
const parameterError = 8

// 闹钟不存在
const alarmNotExist = 9

// 闹钟已存在
const alarmAlreadyExist = 10

// 闹钟数量达到限制
const alarmCountLimit = 11

// MARK: - 重复星期
const repeatMonday = 1 << 0
const repeatTuesday = 1 << 1
const repeatWednesday = 1 << 2
const repeatThursday = 1 << 3
const repeatFriday = 1 << 4
const repeatSaturday = 1 << 5
const repeatSunday = 1 << 6
const repeatEnable = 1 << 7


// MARK: - 设置分组
const YCSettingCommandID = 0x01

// MARK: - 查询分组
const YCQueryCommandID = 0x02
const setTime = 0x00
const setAlarmClock = 0x01
const setGoal = 0x02
const setUserInfo = 0x03
const setUnit = 0x04
const setSedentaryReminder = 0x05
const setAntiLost = 0x06
const setWearingPosition = 0x08

const setHeartRateAlarm = 0x0B
const setHeartRateMonitoringMode = 0x0C
const setFindPhone = 0x0D
const setReset = 0x0E
const setDoNotDisturb = 0x0F
const setLanguage = 0x12
const setWristBrightScreen = 0x13
const setDisplayBrightness = 0x14
const setSkinColor = 0x15
const setTheme = 0x19

const setTemperatureAlarm = 0x1F
const setTemperatureMonitoringMode = 0x20

// MARK: - 查询分组
const queryBasicInfo = 0x00
const querySupportFunction = 0x01
const queryMacAddress = 0x02
const queryModel = 0x03
const queryTheme = 0x09
const queryElectrodeLocation = 0x0A
const queryMCU = 0x1b
const queryRealTimeTemperature = 0x0e


// MARK: - App控制分组
const YCAppControlCommandID = 0x03
const appControlFindDevice = 0x00
const appControlBloodPressureCalibration = 0x03
const appControlRealTimeDataUpload = 0x09
const appControlWaveUploadControl = 0x0B
const appControlSportControl = 0x0C
const appControlSystemOperator = 0x16
const appControlTodayWeather = 0x12
const appControlTomorrowWeather = 0x13
const appControlBloodGlucoseCalibration = 0x31
const appControlUricAcidCalibration = 0x37
const appControlBloodFatCalibration = 0x38

// MARK: - 同步设备健康数据的分组
const YCHealthDataCommandID = 0x05

const queryHealthDataStep = 0x02
const queryHealthDataSleep = 0x04
const queryHealthDataHeartRate = 0x06
const queryHealthDataBloodPressure = 0x08
const queryHealthDataCombinedData = 0x09
const queryHealthDataInvasiveMeasurement = 0x2F
const queryHealthDataHistoryBody = 0x33

const replyHealthDataStep = 0x11
const replyHealthDataSleep = 0x13
const replyHealthDataHeartRate = 0x15
const replyHealthDataBloodPressure = 0x17
const replyHealthDataCombinedData = 0x18
const replyHealthDataInvasiveMeasurement = 0x30

const deleteHealthDataStep = 0x40
const deleteHealthDataSleep = 0x41
const deleteHealthDataHeartRate = 0x42
const deleteHealthDataBloodPressure = 0x43
const deleteHealthDataCombinedData = 0x44
const deleteHealthDataInvasiveMeasurement = 0x4C
const deleteHealthDataHistoryBody = 0x4E
const healthDataBblockConfirm = 0x80

// MARK: - 设备控制分组
const YCDeviceControlCommandID = 0x04
// 手环返回 APP 启动单次测量结果
const measureStatus = 0x0E
const measureECGStatus = 0x0B

// MARK: - 实时上传
const YCRealTimeDataCommandID = 0x06
const realStepDataUpload = 0x00
const realHeartRateDataUpload = 0x01
const realBloodOxygenUpload = 0x02
const realBloodPressureUpload = 0x03
const realHrvUpload = 0x04



// MARK: - 闹钟类型 
const alarmTypeWakeUp = 0
const alarmTypeSleep = 1
const alarmTypeExercise = 2
const alarmTypeMedicine = 3
const alarmTypeAppointment = 4
const alarmTypeParty = 5
const alarmTypeMeeting = 6
const alarmTypeCustom = 7

// MARK: - 实时数据上传类型

// 步数
const realTimeDataTypeStep = 0

// 心率
const realTimeDataTypeHeartRate = 1

// 血氧 (保留)
const realTimeDataTypeBloodOxygen = 2

// 血压 
const realTimeDataTypeBloodPressure = 3

// hrv (保留)
const realTimeDataTypeHrv = 4
const startHrv = 0x03

// 呼吸率 (保留)
const realTimeDataTypeRespirationRate = 5

// 运动模式数据 (保留)
const realTimeDataTypeseSportMode = 6

// 运动组合数据 (保留)
const realTimeDataTypeCombinedData = 7

// ECG
const queryHealthDataECG = 0x00

// MARK: - 接收实时数据类型
const receivedRealTimeStep = 0x0
const receivedRealTimeHeartRate = 0x01
const receivedRealTimeBloodOxygen = 0x02
const receivedRealTimeBloodPressure = 0x03
const receivedRealTimePPG = 0x04
const receivedRealTimeECG = 0x05
const receivedRealTimeHrv = 0x06
const receivedRealTimePressure = 0x10
const receivedRealTimeMonitoringMode = 0x0D // 接收监测数据(包含运动数据)
const findPhone = 0x00 // 寻找手机

// MARK: - 天气类型
const weatherTypeUnknow = 0
const weatherTypeSunny = 1
const weatherTypeCloudy = 2
const weatherTypeWind = 3
const weatherTypeRain = 4
const weatherTypeSnow = 5
const weatherTypeFoggy = 6

// MARK: - 血糖校准模式
const bloodGlucoseCalibrationModeBeforeMeal = 0 // 餐前
const bloodGlucoseCalibrationModeAfterMeal = 1 // 餐后

// MARK: - 波形上传控制
const waveUploadStateOff = 0 // 关闭
const waveUploadStateUploadWithOutSerialnumber = 1 // 开始上传且上传包不带序号
const waveUploadStateUploadSerialnumber = 2 // 开始上传且上传包带8位序号

const waveUploadDataTypePPG = 0 // 光电波形
const waveUploadDataTypeECG = 1 // 心电波形
const waveUploadDataTypeMultiAxisSensor = 2 // 多轴传感器波形
const waveUploadDataTypeAmbientLight = 3 // 环境光

//采集指令
const YCCollectDataTypeDataCommandID = 0x07
const YCCollectDataKeyQuery = 0
const YCCollectDataKeyRetrieveIndex = 1
const YCCollectDataKeyRetrieveTimeStamp = 2
const YCCollectDataKeyReceiveData = 0x10
const YCCollectDataKeyReceiveCheckInfo = 0x20
const YCCollectDataKeyDeleteIndex = 0x30
const YCCollectDataKeyDeleteTimeStamp = 0x31

const YCCollectDataEcg = 0
const YCCollectDataPpg = 1

// 心电指令key
const electrodeKey = 0x14

// MARK: - 饮食建议
// 指令
const YCAppDistributeHealthInfoCommandID = 0x0B
const startSendHealthInfoSummary = 0x00
const sendHealthInfoDetailData = 0x01
const sendHealthInfoCheckInfo = 0x02

// 健康内容类型
const YCDistributeHealthInfoTypeHealthAdvice = 0x01 // 健康建议
const YCDistributeHealthInfoTypeNutritiousMeals = 0x02 // 营养膳食
const YCDistributeHealthInfoTypeWorkOut = 0x03 // 运动健身
const YCDistributeHealthInfoTypeMentalSleep = 0x04 // 心理睡眠
const YCDistributeHealthInfoTypeTraditionalChineseMedicine = 0x05 // 中医养生
const YCDistributeHealthInfoTypeHealthFoodData = 0x06 // 食材数据

// 测量控制
// 控制类型
const stop = 0x00 //关闭
const start = 0x01 // 单次测量
const continuous = 0x02 // 连续测量、检测
// 功能类型
const measureHrData = 0x00 // 心率
const measureBpData = 0x01 // 血压
const measureBoData = 0x02 // 血氧
const measureBrData = 0x03 // 呼吸率
const measureTempData = 0x04 // 体温
const measureBsData = 0x05 // 血糖
const measureUaData = 0x06 // 尿酸
const measureBkData = 0x07 // 血酮
const measureEdaData = 0x08 // EDA
const measureHfData = 0x09 // 血脂
const measureHrvData = 0x0A // hrv
const measurePpgData = 0x0B // ppg
const measurePressData = 0x0C // 压力


// 外设指令
const peripheralID = 0x0F // 外设模块通用Command ID
const count = 0x00 // 上传次数

const deviceId1 = 0x01 //设备ID1
const deviceId2 = 0x02 //设备ID2

const peripheralParamP = 0x50 // 字母P十六进制
const peripheralParamE = 0x45 // 字母E十六进制
const peripheralParamR = 0x52 // 字母R十六进制

const peripheralParamCmd1 = 0x01 // 操作指令 cmd 1
const peripheralParamCmd2 = 0x02 // 操作指令 cmd 2

const queryDeviceIdKey = 0x01 // 获取设备ID Key
const queryElectricityInformationKey = 0x03 // 获取电量信息 Key
const queryDeviceStatusKey = 0x51 // 获取设备状态 Key
const queryDeviceGearPositionKey = 0x51 // 获取设备支持档位数 Key
const setDeviceOperatingModeKey = 0x50 // 设置运行模式 key
const deviceControlKey = 0x04 // 设备控制 Key
const peripheraModeControlKey = 0x04 // 关机、重启 Key

module.exports = {

  secondForThirtyYear,
  secondFromGMT,
  deepSleepFlag,
  lightSleepFlag,
  remSleepFlag,
  awakeSleepFlag,

  // 错误码
  succeed,
  failed,
  timeout,
  unavailable,
  dataError,
  crcError,
  noRecord,
  typeNotSupport,
  parameterError,
  alarmNotExist,
  alarmAlreadyExist,
  alarmCountLimit,

  // MARK: - 重复取值
  repeatMonday,
  repeatTuesday,
  repeatWednesday,
  repeatThursday,
  repeatFriday,
  repeatSaturday,
  repeatSunday,
  repeatEnable,

  // 心电指令key
  electrodeKey,

  // 设置分组
  YCSettingCommandID,
  setTime,
  setGoal,
  setAlarmClock,
  setUserInfo,
  setSedentaryReminder,
  setUnit,
  setAntiLost,
  setWearingPosition,
  setHeartRateAlarm,
  setHeartRateMonitoringMode,
  setFindPhone,
  setReset,
  setDoNotDisturb,
  setLanguage,
  setWristBrightScreen,
  setDisplayBrightness,
  setSkinColor,
  setTheme,
  setTemperatureAlarm,
  setTemperatureMonitoringMode,

  // 查询分组
  YCQueryCommandID,
  queryBasicInfo,
  querySupportFunction,
  queryMacAddress,
  queryModel,
  queryTheme,
  queryElectrodeLocation,
  queryMCU,
  queryRealTimeTemperature,

  // MARK: - AppControl
  YCAppControlCommandID,
  appControlFindDevice,
  appControlBloodPressureCalibration,
  appControlRealTimeDataUpload,
  appControlWaveUploadControl,
  appControlSportControl,
  appControlSystemOperator,
  appControlTodayWeather,
  appControlTomorrowWeather,
  appControlBloodGlucoseCalibration,
  appControlUricAcidCalibration,
  appControlBloodFatCalibration,

  // 同步历史数据
  YCHealthDataCommandID,
  queryHealthDataStep,
  queryHealthDataSleep,
  queryHealthDataHeartRate,
  queryHealthDataBloodPressure,
  queryHealthDataCombinedData,
  queryHealthDataInvasiveMeasurement,
  queryHealthDataHistoryBody,

  replyHealthDataStep,
  replyHealthDataSleep,
  replyHealthDataHeartRate,
  replyHealthDataBloodPressure,
  replyHealthDataCombinedData,
  replyHealthDataInvasiveMeasurement,

  deleteHealthDataStep,
  deleteHealthDataSleep,
  deleteHealthDataHeartRate,
  deleteHealthDataBloodPressure,
  deleteHealthDataCombinedData,
  deleteHealthDataHistoryBody,
  deleteHealthDataInvasiveMeasurement,

  healthDataBblockConfirm,

  // MARK: - 设备控制分组
  YCDeviceControlCommandID,


  // MARK: - 实时上传
  YCRealTimeDataCommandID,
  realStepDataUpload,
  realHeartRateDataUpload,
  realBloodOxygenUpload,
  realBloodPressureUpload,
  realHrvUpload,

  // MARK: - 闹钟类型 
  alarmTypeWakeUp,
  alarmTypeSleep,
  alarmTypeExercise,
  alarmTypeMedicine,
  alarmTypeAppointment,
  alarmTypeParty,
  alarmTypeMeeting,
  alarmTypeCustom,

  // MARK: - 实时数据上传类型

  realTimeDataTypeStep,
  realTimeDataTypeHeartRate,
  realTimeDataTypeBloodOxygen,
  realTimeDataTypeBloodPressure,
  realTimeDataTypeHrv,
  receivedRealTimePressure,
  realTimeDataTypeRespirationRate,
  realTimeDataTypeseSportMode,
  realTimeDataTypeCombinedData,
  queryHealthDataECG,
  startHrv,

  receivedRealTimeStep,
  receivedRealTimeHeartRate,
  receivedRealTimeBloodOxygen,
  receivedRealTimeBloodPressure,
  receivedRealTimePPG,
  receivedRealTimeECG,
  receivedRealTimeHrv,
  receivedRealTimeMonitoringMode,
  findPhone,

  //采集指令
YCCollectDataTypeDataCommandID,
YCCollectDataKeyQuery,
YCCollectDataKeyRetrieveIndex,
YCCollectDataKeyRetrieveTimeStamp,
YCCollectDataKeyReceiveData,
YCCollectDataKeyReceiveCheckInfo,
YCCollectDataKeyDeleteIndex,
YCCollectDataKeyDeleteTimeStamp,

YCCollectDataEcg,
YCCollectDataPpg,

  // MARK: - 天气类型
  weatherTypeUnknow,
  weatherTypeSunny,
  weatherTypeCloudy,
  weatherTypeWind,
  weatherTypeRain,
  weatherTypeSnow,
  weatherTypeFoggy,

  // MARK: - 血糖校准模式
  bloodGlucoseCalibrationModeBeforeMeal, // 餐前
  bloodGlucoseCalibrationModeAfterMeal, // 餐后

  // MARK: - 波形上传控制
  waveUploadStateOff,
  waveUploadStateUploadWithOutSerialnumber,
  waveUploadStateUploadSerialnumber,

  waveUploadDataTypePPG,
  waveUploadDataTypeECG,
  waveUploadDataTypeMultiAxisSensor,
  waveUploadDataTypeAmbientLight,

  // MARK: - 健康饮食指令
  YCAppDistributeHealthInfoCommandID,
  startSendHealthInfoSummary,
  sendHealthInfoDetailData,
  sendHealthInfoCheckInfo,

  // 健康内容类型
  YCDistributeHealthInfoTypeHealthAdvice, // 健康建议
  YCDistributeHealthInfoTypeNutritiousMeals, // 营养膳食
  YCDistributeHealthInfoTypeWorkOut, // 运动健身
  YCDistributeHealthInfoTypeMentalSleep, // 心理睡眠
  YCDistributeHealthInfoTypeTraditionalChineseMedicine, // 中医养生
  YCDistributeHealthInfoTypeHealthFoodData, // 食材数据

  // 外设模块Command ID
  peripheralID,
  count,
  deviceId1,
  deviceId2,
  peripheralParamP,
  peripheralParamE,
  peripheralParamR,
  peripheralParamCmd1,
  peripheralParamCmd2,
  queryElectricityInformationKey,
  queryDeviceStatusKey,
  queryDeviceGearPositionKey,
  setDeviceOperatingModeKey,
  deviceControlKey,
  peripheraModeControlKey,
  queryDeviceIdKey,

  // 手环返回 APP 启动单次测量结果
  measureStatus, // 心率
  measureECGStatus, // ECG
  // 测量控制
  stop,
  start,
  continuous,
  // 功能类型
  measureHrData,
  measureBpData,
  measureBoData,
  measureBrData,
  measureTempData,
  measureBsData,
  measureUaData,
  measureBkData,
  measureEdaData,
  measureHfData,
  measureHrvData,
  measurePpgData,
  measurePressData,
}